﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections.ObjectModel;

//TODO:Remove the IntGenes, all the int-values will be decided when the doubles are mutliplied by a max.

namespace EvoSim.Simulation
{
	public interface I_IDObject
	{
		string ID { get; }
		string Name { get; set; }
	}

	public abstract class IDObject : I_IDObject
	{
		static List<string> idList = new List<string>();
		public static ReadOnlyCollection<string> IDList;

		static Dictionary<string, int> idMap = new Dictionary<string, int>();

		/// <summary>
		/// Identifies a single target, so that when inheriting it you can see where the target is originally from.
		/// </summary>
		public string ID { get; private set; }

		/// <summary>
		/// The name of the target.
		/// </summary>
		public string Name { get; set; }

		static IDObject()
		{
			IDList = new ReadOnlyCollection<string>(idList);
		}

		public IDObject()
		{
			Name = this.GetType().Name;
			ID = GetUniqueID(this.GetType().Name);

			idList.Add(ID);
		}
		public IDObject(string name)
		{
			ID = GetUniqueID(this.GetType().Name);
			Name = name;

			idList.Add(ID);
		}
		public IDObject(string name, string id)
		{
			ID = id;
			Name = name;
		}

		public static string GetUniqueID(string firstPart)
		{
			if (!idMap.ContainsKey(firstPart))
				idMap.Add(firstPart, 0);

			string id = firstPart + idMap[firstPart]++;

			return id;
		}
	}
}
